package cm.tidudada.aspect;

import cm.tidudada.anno.ChangeDataSource;
import cm.tidudada.support.DynamicDataSourceContextHolder;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;

@Aspect
public class DataSourceAspect implements Ordered {

    // 更改数据源
    @Before(value = "@annotation(changeDataSource)")
    public void before(JoinPoint joinPoint , ChangeDataSource changeDataSource){
        DynamicDataSourceContextHolder.setDataSourceKey(changeDataSource.value());
    }


    // 需要优先
    @Override
    public int getOrder() {
        return -1;
    }
}
